def minSubArrayLen(target, nums):
    if not nums:
        return 0
    res = len(nums) + 1
    total = 0
    i, j = 0, 0
    while j < len(nums):
        total += nums[j]
        j += 1
        while total >= target:
            res = min(res, j - i)
            total -= nums[i]
            i += 1
    if res == len(nums) + 1:
        return 0
    return res


target = 7
nums = [2, 3, 1, 2, 4, 3]
print(minSubArrayLen(target, nums))  # 2
